# -*- coding:utf-8 -*-
import pymysql.cursors
def update_car_info(result,INSURE_CAR_ID):
    connection = pymysql.connect(host='120.55.189.14',
                                 user='insurance',
                                 # password='123456',
                                 password='insurance',
                                 db='insurance',
                                 charset='utf8mb4',
                                 cursorclass=pymysql.cursors.DictCursor)
    sql3 = "UPDATE insure_car SET CUST_NAME=%s,PLATE_NUMBER=%s,VEHICLE_BRAND=%s,FIRST_REGISTER=%s,ENGINE_NO=%s,FLAG=1,CITY_CODE=%s  WHERE INSURE_CAR_ID = %s"
    try:
        with connection.cursor() as cursor:
            cursor.execute(sql3, (result['hCAppNme'], result['gCPlateNo'], result['gCNoticeType'], result['CFstRegYm'], result['CEngNo'],result['cityCode'], INSURE_CAR_ID))
        connection.commit()
    except:
        connection.close()
    finally:
        connection.close()
# if __name__=="__main__":
#     result={
#         "CEngNo": "M88601",  # 发动机号
#         "RejectDate": "20991231",  #
#         "color": "白",
#         "CFstRegYm": "2016-01-06",  # 注册时间
#         "gNDisplacement": "1.598",  # 排量
#         "pmUseType": "非营运",
#         "MadeFactory": "一汽-大众汽车有限公司",
#         "IneffectualDate": "20180131",  # 校验有效日期止
#         "EngineType": "汽油",  # 发动机类型
#         "gCValidateCode": "XBQE",  #
#         "gCBrandId": "大众牌",  # 车辆拼配
#         "Haulage": "0",
#         "RImportFlag": "六座以下客车",
#         "gCPlateNo": "苏NPW232",
#         "LastCheckDate": "20160106",  # 上次年检日期
#         "status": "违法未处理",  # 交管车辆机动车状态代码
#         "gNSeatNum": "5",  # 座位数
#         "NCurbWt": "1.3",  # 整备质量
#         "useType": "",
#         "RVehlcleTonnage": "0.0",
#         "TransferDate": "",
#         "gCNoticeType": "FV7166BAMBG",  # 车辆型号
#         "gCRegVhlTyp": "K33",  # 车辆类型
#         "BrandEN": "",
#         "hCAppNme": "梁永党",  # 车主姓名
#         "gCFrmNo": "LFV2A11K8F4192886",
#         "gCPlateTyp": "02",  # 牌照类型
#         "checkNo": "72CICP320017001483947471404268",  #
#         "SalesChannl": "国产",  # 汽车厂类型
#         "VehlclePrice": "0"
#     }
#     update_car_info(result,'58')

def rollbackT():
    connection = pymysql.connect(host='120.55.189.14',
                                 user='insurance',
                                 # password='123456',
                                 password='insurance',
                                 db='insurance',
                                 charset='utf8mb4',
                                 cursorclass=pymysql.cursors.DictCursor)
    sql5 = "UPDATE car_premium SET BAO_E='1011111111' WHERE PREMIUM_ID='15209'"
    try:
        with connection.cursor() as cursor:
            cursor.execute(sql5)
            print 1/0
            connection.commit()
    except:
        print 1
        connection.rollback()
        connection.close()
if __name__=="__main__":
    rollbackT()